package com.allwees.bs.c.module.user.repository;

import com.allwees.bs.c.module.base.repository.BaseRepository;
import com.allwees.bs.c.module.user.entity.UserCashLogEntity;
import com.allwees.bs.core.model.coupon.constant.ECashLogType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserCashLogRepository extends BaseRepository<UserCashLogEntity, Long> {

    @Query(value = "select t from UserCashLogEntity t where isDeleted = 0 and status = 0 and userUuid=:userUuid and cashActiveUuid=:cashActiveUuid")
    List<UserCashLogEntity> findCountByUserUuidAndCashActiveUuid(String userUuid, String cashActiveUuid);

    @Query(value = "select t from UserCashLogEntity t where isDeleted = 0 and status = 0 and userUuid=:userUuid order by createdAt desc")
    Page<UserCashLogEntity> findByUserUuid(String userUuid, Pageable page);

    @Query(value = "select t from UserCashLogEntity t where isDeleted = 0 and userUuid=:userUuid and logType = :logType")
    PageImpl<UserCashLogEntity> findByUserUuidAndLogType(String userUuid, ECashLogType logType, Pageable page);

    List<UserCashLogEntity> findAllByUserUuid(String userUuid);
}
